<?php
//function bbcode($tag, $text, $compile=false)
//{
//    $x = strlen($tag);
//
//    $tag1='[/'.$tag."]";
//    $tag = '['.$tag.']';
//    $items = array();
//   
//    while (strpos($text,$tag) !== false)
//            {
//               
//           //     echo substr($text,strpos($text,$tag) + $x + 2, strpos($text,$tag1)-(strpos($text,$tag) + $x + 2))."<br/>";
//                $source =substr($text,strpos($text,$tag) + $x + 2, strpos($text,$tag1)-(strpos($text,$tag) + $x + 2));
//                if ($tag == '[img]')
//                    $replacewith= "<a href='/urp/media/transfer/img/".$source."'><img src='/urp/media/filter/medium/img/".$source."'/></a>";
//                else if ($tag == '[video]') {
//                }
//                else if ($tag == '[audio]') {
//                }
//                $text=substr_replace ($text, $replacewith, strpos($text,$tag), strpos($text,$tag1)-strpos($text,$tag) + $x + 3);
//            }
//    return $text;
//    }

    function bb_code($string) { 
        $tags = 'b|i|size|color|center|quote|url|img|audio|video'; 
        while (preg_match_all('`\[('.$tags.')=?(.*?)\](.+?)\[/\1\]`', $string, $matches)) foreach ($matches[0] as $key => $match) { 
            list($tag, $param, $innertext) = array($matches[1][$key], $matches[2][$key], $matches[3][$key]); 
            switch ($tag) { 
                case 'b': $replacement = "<strong>$innertext</strong>"; break; 
                case 'i': $replacement = "<em>$innertext</em>"; break; 
                case 'size': $replacement = "<span style=\"font-size: $param;\">$innertext</span>"; break; 
                case 'color': $replacement = "<span style=\"color: $param;\">$innertext</span>"; break; 
                case 'center': $replacement = "<div class=\"centered\">$innertext</div>"; break; 
                case 'quote': $replacement = "<blockquote>$innertext</blockquote>" . $param? "<cite>$param</cite>" : ''; break; 
                case 'url': $replacement = '<a href="' . ($param? $param : $innertext) . "\">$innertext</a>"; break; 
                case 'img': 
//                    list($width, $height) = preg_split('`[Xx]`', $param); 
//                    " . (is_numeric($width)? "width=\"$width\" " : '') . (is_numeric($height)? "height=\"$height\" " : '') . '
                    $replacement ="<a href='/urp/media/transfer/img/".$innertext."'><img src='/urp/media/filter/medium/img/".$innertext."'/></a>";
                break; 
                case 'video': 
                    $videourl = parse_url($innertext); 
                    if (isset($videourl['query'])) {
                    parse_str($videourl['query'], $videoquery); 
                    if (strpos($videourl['host'], 'youtube.com') !== FALSE) $replacement = '<embed src="http://www.youtube.com/v/' . $videoquery['v'] . '" type="application/x-shockwave-flash" width="425" height="344"></embed>'; 
                    if (strpos($videourl['host'], 'google.com') !== FALSE) $replacement = '<embed src="http://video.google.com/googleplayer.swf?docid=' . $videoquery['docid'] . '" width="400" height="326" type="application/x-shockwave-flash"></embed>';                
                    }
                    else {
                         $aperture="'avc1.42E01E, mp4a.40.2'";
$replacement= '<div class="video-js-box"><video class="video-js" width="400" height="300" controls preload poster=""><source src="/urp/media/transfer/vid/'.$innertext.'" type="video/mp4; codecs='.$aperture.'" /></video></div>';
                    }
               break; 
               case 'audio':
                   $aperture="'avc1.42E01E, mp4a.40.2'";
$replacement=              '<div class="audio"><div class="video-js-box"><video class="video-js" width="300" height="30" controls preload poster=""><source src="/urp/media/transfer/aud/'.$innertext.'" type="video/mp4; codecs='.$aperture.'" /></video></div></div>';
               break;
            } 
            $string = str_replace($match, $replacement, $string); 
        } 
        return $string; 
    }
//    http://www.youtube.com/watch?v=v5QLZ4oj_6A
?> 